#include "viewer-audio-file.h"

struct _ViewerAudioFile {
    ViewerFile parent_instance;
};

#if defined(INF_EDITABLE) || defined(INF_LOSSY)
#include "viewer-editable.h"
static void viewer_audio_file_editable_interface_init (ViewerEditableInterface *iface);
//ViewerAudioFile的父类ViewerFile的接口实现入口(句柄)
static ViewerEditableInterface *viewer_af_par_edit_inf = NULL;
#endif

#ifdef INF_LOSSY
#include "viewer-editable-lossy.h"
static void viewer_audio_file_editable_lossy_interface_init (ViewerEditableLossyInterface *iface);
static ViewerEditableLossyInterface *viewer_af_par_elossy_inf = NULL;
#endif

G_DEFINE_TYPE_WITH_CODE (ViewerAudioFile, viewer_audio_file, VIEWER_TYPE_FILE,
#ifdef INF_EDITABLE
                         G_IMPLEMENT_INTERFACE (VIEWER_TYPE_EDITABLE,
                                                viewer_audio_file_editable_interface_init)
#endif
#ifdef INF_LOSSY
                         G_IMPLEMENT_INTERFACE (VIEWER_TYPE_EDITABLE_LOSSY,
                                                viewer_audio_file_editable_lossy_interface_init)

#endif
)

#if defined(INF_EDITABLE) || defined(INF_LOSSY)
static void
viewer_audio_file_editable_save (ViewerEditable  *self,
                                 const gchar *name)
{
    ViewerAudioFile *vaf = VIEWER_AUDIO_FILE (self);
    g_print ("Audio file implementation of editable interface save method.\n");
    viewer_af_par_edit_inf->save(self, name);
}

static void
viewer_audio_file_editable_interface_init(ViewerEditableInterface *iface) {
    viewer_af_par_edit_inf =  g_type_interface_peek_parent(iface);
    iface->save = viewer_audio_file_editable_save;
}

#endif

#ifdef INF_LOSSY
static void
viewer_audio_file_editable_lossy_compress(ViewerEditableLossy *self) {
    ViewerAudioFile *vaf = VIEWER_AUDIO_FILE (self);
    g_print ("Audio file implementation of editable lossy interface compress method.\n");
    viewer_af_par_elossy_inf->compress(self);
        
}

static void
viewer_audio_file_editable_lossy_interface_init(ViewerEditableLossyInterface *iface) {
    viewer_af_par_elossy_inf =  g_type_interface_peek_parent(iface);
    iface->compress = viewer_audio_file_editable_lossy_compress;
}

#endif

void viewer_audio_file_open (ViewerFile  *self, GError **error) {
    ViewerFileClass *vfc = VIEWER_FILE_CLASS(viewer_audio_file_parent_class);
    g_print("calling %s\n", __func__);
    g_return_if_fail(vfc->open != NULL);
    vfc->open(self, error);   
}

static void viewer_audio_file_init(ViewerAudioFile *self) {
    /* Instance variable initialisation code. */
    g_print("calling %s\n", __func__);
}


static void
viewer_audio_file_class_init (ViewerAudioFileClass *klass) {
    ViewerFileClass *parent_class = VIEWER_FILE_CLASS(klass);
    g_print("calling %s\n", __func__);
    parent_class->open = viewer_audio_file_open;
}
